#include <iostream>
#include <unistd.h>
#include <signal.h>
void st(int st_sig){
   std::cout<<"成功捕捉2号信号"<<st_sig<<std::endl;
}
void sn(int sn_sig){
    std::cout<<"成功捕捉40号信号"<<sn_sig<<std::endl;

}
void PrintPending(sigset_t &pending)
{
    std::cout << "curr process[" << getpid() << "]pending: ";
    for (int signo = 40; signo >= 1; signo--)
    {
        if (sigismember(&pending, signo))
        {
            std::cout << 1;
        }
        else
        {
            std::cout << 0;
        }
    }
    std::cout << "\n";
}
 int main(){
   int cnt=5;
   signal(SIGINT,st);
   signal( SIGRTMIN+6 ,sn);
   sigset_t block_2,block_40,old2,old40;
   sigemptyset(&block_2);
   sigemptyset(&block_40);
   sigemptyset(&old2);
   sigemptyset(&old40);
   //sigaddset(&block_2,2);
  sigaddset(&block_40,40);
  // sigprocmask(SIG_SETMASK,&block_2,&old2);
   sigprocmask(SIG_SETMASK,&block_40,&old40);
   while(cnt--){
     sigset_t s2,s40;
     //sigpending(&s2);
     sigpending(&s40);
     //PrintPending(s2);
     PrintPending(s40);
    sleep(1);
    
   }

    std::cout << "解除对2号信号的屏蔽!!!" << std::endl;
        sigprocmask(SIG_SETMASK, &old2, &block_2);
    sleep(1);
  return 0;
 }